package com.qf.fmall.service.impl;

import com.qf.fmall.dao.UserAddrMapper;
import com.qf.fmall.entity.UserAddr;
import com.qf.fmall.service.UserAddrService;
import com.qf.fmall.vo.ResStatus;
import com.qf.fmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service("userAddrService")
public class UserAddrServiceImpl implements UserAddrService {
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private UserAddrMapper userAddrMapper;

    @Override
    public ResultVo list(Integer userid) {
        Example example = new Example(UserAddr.class);
        example.createCriteria()
                .andEqualTo("userId", userid);
        List<UserAddr> userAddrs = userAddrMapper.selectByExample(example);
        ResultVo resultVo = new ResultVo();
        if (userAddrs.size() == 0) {
            resultVo.setCode(ResStatus.NO);
            resultVo.setMsg("地址查询失败");
        } else {
            resultVo.setCode(ResStatus.OK);
            resultVo.setMsg("地址查询成功");
            resultVo.setData(userAddrs);
        }
        return resultVo;
    }
}
